package com.example.myapplication.model;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;

import java.util.List;

public class OrderAdapter extends  RecyclerView.Adapter<OrderAdapter.ViewHolder> {
    private  List<Order> mOrderList;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_item,parent, false);

        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            Order order = mOrderList.get(position);
            holder.order_number.setText(order.order_Number);
            holder.price.setText("￥"+order.price);
    }

    @Override
    public int getItemCount() {
        return mOrderList.size();
    }

    static  class ViewHolder extends  RecyclerView.ViewHolder{

        TextView order_number;
        TextView price;

        public ViewHolder(View view){
            super(view);
            order_number = view.findViewById(R.id.order_number_2);
            price = view.findViewById(R.id.total_amount_order);
        }
    }

    public  OrderAdapter(List<Order> list){
        mOrderList = list;
    }
}
